package SpaceIT.pages.Admin;

import java.util.ArrayList;

import model.dao.KhuyenMaiDAO;
import model.pojo.KhuyenMai;
import model.pojo.NhanVien;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Grid;

import SpaceIT.pages.Index;

public class DanhSachKhuyenMai {
	@ApplicationState
    private NhanVien NV;
	public Object onActivate()
	{
		if(NV.isDangNhap()==false)
		{			
			//NV.setDangNhap(false);
			return Index.class;
		}
		return null;
	}
	@Property
	@Persist
	private String message;
	public String EmptyMessage(){
		message = "";
		return "";
	}
	private KhuyenMai KM;
	public KhuyenMai getKM() {
		return KM;
	}
	public void setKM(KhuyenMai kM) {
		KM = kM;
		rowNoWithCurrentPage++;
	}
	@Property  
	private int noOfRowsPerPage=15; 
	private int rowNoWithCurrentPage;  
	 @Component(id = "myGrid")  
	 private Grid grid;  
	 public int getRowNo() {  
       int page = grid.getCurrentPage();  
       int rowNo = (page - 1) * noOfRowsPerPage + rowNoWithCurrentPage;  
 
       return rowNo;  
   }  
	 public String getMyRowClass() {  
       return (getRowNo() % 2 == 0 ? "even" : "odd");  
   }  
	 public ArrayList<KhuyenMai> getDSKhuyenMai()
	 {
		 return KhuyenMaiDAO.LayDSKhuyenMai();
	 }
	 @OnEvent(component="Xoa")
	void Xoa(String str)
	{
		 boolean kq = KhuyenMaiDAO.XoaKhuyenMai(Integer.parseInt(str));
		 if(kq ==true)
		 {
			 message="Xóa Khuyến Mãi Thành Công";
		 }
		 else
			 message="Xóa Khuyến Mãi Thất Bại";
		// System.out.print(str);;
	}
}
